package com.topica.database.task;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;

import com.topica.database.DataBaseHelper;
import com.topica.database.callback.OnGetListWeekListener;
import com.topica.object.WeekItem;

public class GetListWeekTask extends TopicaDBTask {
	private static final String TAG = "GetListWeek";
	private ArrayList<WeekItem> items;
	private OnGetListWeekListener listener;
	private String courseId;

	public GetListWeekTask(Context context, String courseId) {
		super(context);
		this.courseId = courseId;
	}

	@Override
	protected Integer doInBackground(Void... params) {
		DataBaseHelper myDbHelper = new DataBaseHelper(
				context.getApplicationContext());
		items = myDbHelper.getListWeek(courseId);
		myDbHelper.close();
		return OK;
	}

	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		if (result == OK) {
			listener.onGetListWeekListener(items);
		} else {
			Log.e(TAG, "Co loi trong qua trinh lay danh sach Week");
		}
	}

	public void setOnGetListWeekListener(OnGetListWeekListener listener) {
		this.listener = listener;
	}

}
